208 十進位換算
methond 1num = eval(input().strip()) if num == 10: print("A") elif num == 11: print("B") elif num == 12: print("C") elif num == 13: print("D") elif num == 14: print("E") elif num == 15: print("F") else: print(num)
methond 2
num = eval(input().strip()) if 0<= num <10: hexNum = num else: hexNum = chr(num+55) print(hexNum)
python的內置函數char(x), x作為參數, 十進值得值介於0~255, 也可為16進制的值。並返回一個當前整數對應的 ASCII 字符。
306 迴圈階乘計算
num = int(input().strip()) ans=1 for i in range(1,(num+1)): ans *= i print(ans)
410 繪製等腰三角形
num = int(input()) for x in range(1,num+1): # rows numbers for y in range(num-x): # blanks in columns print(" ",end="") for z in range(2*x-1): # after blanks is * print("*",end="") print()
參考資料:TQC+ Python 3